package com.itheima.web;

import com.itheima.dto.OrderInfoDto;
import com.itheima.entity.Result;
import com.itheima.service.OrderService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Reference
    private OrderService orderService;

    @GetMapping("/sendSmsCode/{telephone}")
    public void sendSmsCode(@PathVariable("telephone") String telephone){
        rabbitTemplate.convertAndSend("wsl","sms",telephone);
    }

    @RequestMapping("/createOrder")
    public Result createOrder(@RequestBody OrderInfoDto orderInfoDto){
        return new Result(orderService.createOrder(orderInfoDto));
    }

    @GetMapping("/successInfo/{orderId}")
    public Result selectOrderSuccessInfo(@PathVariable("orderId") Long orderId){
        return new Result(orderService.selectOrderSuccessInfo(orderId));
    }


}
